package com.blb.order_service.service;

import com.blb.order_service.entity.Goods;
import com.blb.order_service.feign.GoodsFeignClient;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * 访问商品服务中的商品信息
 */
@Service
public class GoodsService {

//    @Autowired
//    private RestTemplate restTemplate;

    @Autowired
    private GoodsFeignClient goodsFeignClient;

    //访问商品服务
//    @HystrixCommand(fallbackMethod = "findGoodsByIdFallback")
    public Goods findGoodsById(Long id){
//        //使用Eureka注册中心实现调用
//        Goods goods = restTemplate.getForObject("http://goods-service/goods/"+id,Goods.class);
//        return goods;
        return goodsFeignClient.findById(id);
    }

//    public Goods findGoodsByIdFallback(Long id){
//        Goods goods = new Goods();
//        goods.setId(id);
//        goods.setAddress("这是回退方法数据");
//        return goods;
//    }
}
